import request from '@/utils/request';
import {AxiosPromise} from 'axios';


// 查询字典类型列表
export function listType(query: DictVO): AxiosPromise<DictVO[]> {
  return request({
    url: '/system/dict/type/list',
    method: 'get',
    params: query
  });
}

// 查询字典类型详细
export function getType(dictId: number | string | undefined): AxiosPromise<DictVO> {
  return request({
    url: '/system/dict/type/' + dictId,
    method: 'get'
  });
}

// 新增字典类型
export function addType(data: DictVO) {
  return request({
    url: '/system/dict/type',
    method: 'post',
    data: data
  });
}

// 修改字典类型
export function updateType(data: DictVO) {
  return request({
    url: '/system/dict/type',
    method: 'put',
    data: data
  });
}

// 删除字典类型
export function delType(dictId: string | number | Array<string | number>) {
  return request({
    url: '/system/dict/type/' + dictId,
    method: 'delete'
  });
}

// 刷新字典缓存
export function refreshCache() {
  return request({
    url: '/system/dict/type/refreshCache',
    method: 'delete'
  });
}

// 获取字典选择框列表
export function optionselect(): AxiosPromise<DictVO[]> {
  return request({
    url: '/system/dict/type/optionselect',
    method: 'get'
  });
}
// ====================data的查询API=========================
// 查询字典数据列表
export function listData(query: DictVO): AxiosPromise<DictVO[]> {
  return request({
    url: '/system/dict/data/list',
    method: 'get',
    params: query
  });
}

// 根据字典类型查询字典数据信息
export function getDataByType(dictType: string): AxiosPromise<DictVO[]> {
  return request({
    url: '/system/dict/data/type/' + dictType,
    method: 'get'
  });
}


// 查询字典数据详细
export function getData(dictId: number): AxiosPromise<DictVO> {
  return request({
    url: '/system/dict/data/' + dictId,
    method: 'get'
  });
}

// 新增字典数据
export function addData(data: DictVO) {
  return request({
    url: '/system/dict/data',
    method: 'post',
    data: data
  });
}

// 修改字典数据
export function updateData(data: DictVO) {
  return request({
    url: '/system/dict/data',
    method: 'put',
    data: data
  });
}

// 删除字典数据
export function delData(dictId: number | Array<number>) {
  return request({
    url: '/system/dict/data/' + dictId,
    method: 'delete'
  });
}


export interface DictVO extends BaseEntity {
  dictId?: number;
  name?: string;
  type?: string;
  isTree?: boolean;
  dataId?: number;
  value: string;
  cssClass?: string;
  listClass?: ElTagType;
  sort?: number;
  remark?: string;
  /** 树结构使用 */
  parentValue?: string,
  parentName?: string,
  children?: DictVO[];
}
